package com.tjc.cloud.util.alipay.controller

import com.alipay.api.AlipayClient
import com.alipay.api.domain.AlipayFundTransUniTransferModel
import com.alipay.api.domain.Participant
import com.alipay.api.request.AlipayFundTransUniTransferRequest
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

@Component
class AlipayController {
    @Autowired
    var alipayClient:AlipayClient?=null
    fun payment(order :Order): Boolean? {
        val model = AlipayFundTransUniTransferModel()
        model.outBizNo =order.id
        model.remark = order.remark
        model.businessParams =order.businessParams
        model.bizScene = "DIRECT_TRANSFER"
        val payeeInfo = Participant()
        payeeInfo.identity =order.alipayid
        payeeInfo.identityType = "ALIPAY_USER_ID"
        model.payeeInfo = payeeInfo
        model.transAmount =String.format("%.2f",(order.amount?:0).toDouble()/100)
        model.productCode = "TRANS_ACCOUNT_NO_PWD"
        model.orderTitle = order.title
        val request = AlipayFundTransUniTransferRequest()
        request.bizModel = model
        val res=alipayClient?.certificateExecute(request)
        return res?.isSuccess
    }
}
interface Order{
    var id:String?
    var remark:String?
    var businessParams:String?
    var alipayid:String?
    var amount:Int?
    var title:String?
}